#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "mem.h"

typedef struct _buff_st_1
{
    int data_len;
    char data[0];
}buff_st_1;

typedef struct _buff_st_2
{
    int data_len;
    char *data;
}buff_st_2;

typedef struct _buff_st_3 
{
    int data_len;
    char data[];
}buff_st_3;

int main()
{
    int n1 = sizeof(buff_st_1);
    int n2 = sizeof(buff_st_2);
    int n3 = sizeof(buff_st_3);

    buff_st_1 *buff1 = (buff_st_1 *)malloc(sizeof(buff_st_1)+100);
    buff_st_2 *buff2 = (buff_st_2 *)malloc(sizeof(buff_st_2));
    buff_st_3 *buff3 = (buff_st_3 *)malloc(sizeof(buff_st_3)+50);

    int n = show_memory();

    strncpy(buff1->data,"hello",100);
    printf("buff1 address:%p,buff1.data_len address:%p,buff1.data address:%p,value:%s\n",
        buff1, &(buff1->data_len), buff1->data,buff1->data);

    buff2->data = (char*)malloc(10);
    printf("buff2 address:%p,buff2.data_len address:%p,buff2.data address:%p\n",
        buff2, &(buff2->data_len), buff2->data);

    strncpy(buff3->data,"world",100);
    printf("buff3 address:%p,buff3.data_len address:%p,buff3.data address:%p,value:%s\n",
        buff3, &(buff3->data_len), buff3->data,buff3->data);

    return 0;
}